<? 
/**
 * Mailer.php
 *
 * The Mailer class is meant to simplify the task of sending
 * emails to users. Note: this email system will not work
 * if your server is not setup to send mail.
 *
 * If you are running Windows and want a mail server, check
 * out this website to see a list of freeware programs:
 * <http://www.snapfiles.com/freeware/server/fwmailserver.html>
 *
 * 
 */
 
//error_reporting(E_STRICT);
date_default_timezone_set('America/Toronto');
require_once('lib/class.phpmailer.php');
class Mailer
{
    var $mail;
   /**
    * sendWelcome - Sends a welcome message to the newly
    * registered user, also supplying the username and
    * password.
    */
    function Mailer(){
       $this->mail = new PHPMailer();
    $this->mail->IsSMTP(); //telling to use smtp
$this->mail->Host       = "smtp.gmail.com"; // SMTP server
//$this->mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$this->mail->SMTPAuth   = true;                  // enable SMTP authentication
$this->mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$this->mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$this->mail->Port       = 465;                   // set the SMTP port for the GMAIL server
$this->mail->Username   = "privateminder@syntechnepal.com";  // GMAIL username
$this->mail->Password   = "alertcam";            // GMAIL password

$this->mail->SetFrom('privateminder@syntechnepal.com', 'Agricare Nepal');

$this->mail->AddReplyTo("privateminder@syntechnepal.com","Agricare Nepal");

    }
   function sendWelcome($name,  $email,$user, $pass){
      $body = $name.",<br/><br/>"
             ."Welcome! You've  been just registered at ".SITE_NAME." with the following information:<br/><br/>"
             ."Username: ".$user."<br/>"
             ."Password: ".$pass."<br/>"
             ."If you ever lose or forget your password, a new "
             ."password will be generated for you and sent to this "
             ."<br/>" .SITE_NAME;

$this->mail->Subject    = "Registration - Agricare Nepal";

$this->mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$this->mail->MsgHTML($body);

$address = $email;
$this->mail->AddAddress($address, $user);

//$this->mail->AddAttachment("images/sec_cam5.jpg");      // attachment
//$this->mail->AddAttachment("images/cam2.jpg"); // attachment

      return $this->mail->Send(); 
   }
   
   /**
    * sendNewPass - Sends the newly generated password
    * to the user's email address that was specified at
    * sign-up.
    */
   function sendNewPass($user, $email, $pass){
      $from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">";
      $subject = "'s Site - Your new password";
      $body = $user.",\n\n"
             ."We've generated a new password for you at your "
             ."request, you can use this new password with your "
             ."username to log in to".SITE_NAME."'s Site.\n\n"
             ."Username: ".$user."\n"
             ."New Password: ".$pass."\n\n"
             ."It is recommended that you change your password "
             ."to something that is easier to remember, which "
             ."can be done by going to the My Account page "
             ."after signing in.\n\n"
             ."-".SITE_NAME;
             
$this->mail->Subject    = SITE_NAME."-Your new password";

$this->mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$this->mail->MsgHTML($body);

$address = $email;
$this->mail->AddAddress($address, $user);

//$this->mail->AddAttachment("images/sec_cam5.jpg");      // attachment

      return $this->mail->Send(); 
   }
};

/* Initialize mailer object */
$mailer = new Mailer;
 
?>
